package com.mobipe.sutto.mina;

import java.net.InetSocketAddress;

import org.apache.mina.transport.socket.SocketAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import com.mobipe.sutto.core.AbstractServer;

/**
 * @author kohachiro
 *
 */
public class Server extends AbstractServer {
	private SocketAcceptor acceptor;
	private static Server instance;

	/**
	 * 
	 */
	public Server() {
    	acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors() + 1);
        acceptor.setReuseAddress(true);
        acceptor.getSessionConfig().setTcpNoDelay(true);
        //acceptor.getSessionConfig().setReuseAddress(true);
		acceptor.setHandler(new ServerHandler());
	}

	@Override
	public void bind() throws Exception {
		System.out.println("Listening on port " + PORT);
		instance.acceptor.bind(new InetSocketAddress(PORT));
		System.in.read();
	}

	public static void main(String[] args) throws Exception {
		instance = new Server();
		instance.start();		
		instance.bind();
	}

	@Override
	public void start() {
		// TODO Auto-generated method stub
		
	}
}
